rm update
[EroBeats.git] / Djinn and Tonic - Erobeats / ScreenTemplate.cpp
blob796fc73001b1a38785f068964dd3788ba32ffd96
1 #include "ScreenTemplate.h"
3 #include "ScreenNames.h"
5 using namespace std;
7 ScreenTemplate::ScreenTemplate()
9 FPSDelay = 32;
10 alpha = 255;
11 fadeRate = 0;
12 std::cout << FPSDelay << "\n";
16 ScreenTemplate::~ScreenTemplate()
20 void ScreenTemplate::gameLoop() {
21 chrono::milliseconds ms = chrono::duration_cast<chrono::milliseconds>(
22 chrono::system_clock::now().time_since_epoch());
24 running = true;
25 long long initial = 0;
26 long long expired = 0;
28 while (running) {
29 ms = chrono::duration_cast<chrono::milliseconds>(
30 chrono::system_clock::now().time_since_epoch());
31 initial = ms.count();
33 processInput();
34 update();
35 play();
36 render();
38 while (expired - initial < FPSDelay) {
39 ms = chrono::duration_cast<chrono::milliseconds>(
40 chrono::system_clock::now().time_since_epoch());
41 expired = ms.count();
45 close();
48 void ScreenTemplate::processInput() {
49 SDL_Event evnt;
50 while (SDL_PollEvent(&evnt)) {
51 switch (evnt.type) {
52 case SDL_QUIT:
53 running = false;
54 *screen = Quit;
55 break;
56 case SDL_MOUSEMOTION:
57 SDL_GetMouseState(&x, &y);
58 break;
59 case SDL_MOUSEBUTTONDOWN:
60 mouseClicked = true;
61 if (evnt.button.button == SDL_BUTTON_LEFT) {
62 mouseClickedL = true;
63 //std::cout << "L\n";
65 else {
66 mouseClickedR = true;
68 break;
70 case SDL_MOUSEBUTTONUP:
71 mouseClicked = false;
72 mouseClickedL = false;
73 mouseClickedR = false;
74 break;
78 bool ScreenTemplate::fadeIn(double durration, SDL_Texture* fadeTexture) {
79 bool done;
80 if (alpha < 255) {
81 if (fadeRate == 0) fadeRate = 255 / (durration / (1 / FPSDelay));
82 alpha += fadeRate;
83 SDL_SetTextureAlphaMod(fadeTexture, alpha);
84 done = false;
86 else {
87 fadeRate = 0;
88 done = true;
90 return done;
93 bool ScreenTemplate::fadeOut(double durration, SDL_Texture* fadeTexture) {
94 bool done;
95 if (alpha > 0) {
96 if (fadeRate == 0) fadeRate = 255 / (durration / (1 / FPSDelay));
97 alpha -= fadeRate;
98 SDL_SetTextureAlphaMod(fadeTexture, alpha);
99 done = false;
101 else {
102 fadeRate = 0;
103 done = true;
105 return done;
108 //fadeOutDurration = milliseconds
109 void ScreenTemplate::fadeOutMusic(int fadeOutDuration) {
110 rsc->bptr->fadeOutBGM(fadeOutDuration);
111 int fadeInDuration;
114 void ScreenTemplate::update() {
116 void ScreenTemplate::play() {
118 void ScreenTemplate::render() {
120 void ScreenTemplate::close(){